﻿CREATE VIEW [dbo].[CofMFabricView]
AS
SELECT     TOP (100) PERCENT dbo.Quote_Tbl.BoatType, dbo.QuoteLineItem_Tbl.LineItem, dbo.QuoteLineItem_Tbl.QuoteLineItemID AS QLIID, 
                      dbo.QuoteLineItem_Tbl.TierID, dbo.QuoteLineItem_Tbl.QuoteID, dbo.Tier_Tbl.Tier, dbo.Construction_Tbl.Construction, dbo.QuoteLineItem_Tbl.NewBRP, 
                      dbo.QuoteLineItem_Tbl.ConstructionID AS ConID, dbo.QuoteSailType_Tbl.SailType, dbo.QuoteLineItem_Tbl.InputArea, dbo.QuoteLineItem_Tbl.FabricID, 
                      dbo.QuoteSailType_Tbl.GenSailTypeID, dbo.QuoteLineItem_Tbl.Weight, dbo.QuoteLineItem_Tbl.BRP, 
                      dbo.GenSailType_Tbl.PriceMultiplier AS SailAdjuster, dbo.Usage_Tbl.UsageType, dbo.GenericYarn_Tbl.YarnType, 
                      dbo.Usage_Tbl.CostFactor AS UsageAdjuster, dbo.Adjuster_Tbl.AdjusterID, dbo.Adjuster_Tbl.BaseAdjuster, dbo.Adjuster_Tbl.OptionAdjuster, 
                      dbo.Adjuster_Tbl.STierAdjuster, dbo.Adjuster_Tbl.MTierAdjuster, dbo.Adjuster_Tbl.LTierAdjuster, dbo.Adjuster_Tbl.ODTierAdjuster, 
                      dbo.Adjuster_Tbl.OEMTierAdjuster, dbo.Adjuster_Tbl.HourlyRate, dbo.Adjuster_Tbl.HourlyCostRate, dbo.Tier_Tbl.TierPriceIndicator, 
                      dbo.CostSailType_Tbl.SailTypeAddFactor, dbo.ConstructionSailType_Tbl.Hoursusedfactor,
                          (SELECT     SailCostFactor
                            FROM          dbo.Fabric_Tbl
                            WHERE      (FabricID = dbo.QuoteLineItem_Tbl.FabricID)) AS SailCostfACTOR,
                          (SELECT     QuoteCost
                            FROM          dbo.Fabric_Tbl AS Fabric_Tbl_4
                            WHERE      (FabricID = dbo.QuoteLineItem_Tbl.FabricID)) AS QuoteCost,
                          (SELECT     DiscountEURO
                            FROM          dbo.Fabric_Tbl AS Fabric_Tbl_3
                            WHERE      (FabricID = dbo.QuoteLineItem_Tbl.FabricID)) AS DiscountEuro,
                          (SELECT     PartCode
                            FROM          dbo.Fabric_Tbl AS Fabric_Tbl_2
                            WHERE      (FabricID = dbo.QuoteLineItem_Tbl.FabricID)) AS PartCode,
                          (SELECT     Width
                            FROM          dbo.Fabric_Tbl AS Fabric_Tbl_1
                            WHERE      (FabricID = dbo.QuoteLineItem_Tbl.FabricID)) AS Width
FROM         dbo.QuoteLineItem_Tbl INNER JOIN
                      dbo.Construction_Tbl ON dbo.QuoteLineItem_Tbl.ConstructionID = dbo.Construction_Tbl.ConstructionID INNER JOIN
                      dbo.QuoteSailType_Tbl ON dbo.QuoteLineItem_Tbl.QuoteSailtypeID = dbo.QuoteSailType_Tbl.QuoteSailTypeID INNER JOIN
                      dbo.CostSailType_Tbl ON dbo.QuoteSailType_Tbl.CostSailtypeID = dbo.CostSailType_Tbl.CostSailTypeID INNER JOIN
                      dbo.GenericYarn_Tbl ON dbo.QuoteLineItem_Tbl.GenericYarnID = dbo.GenericYarn_Tbl.GenericYarnID INNER JOIN
                      dbo.GenSailType_Tbl ON dbo.QuoteSailType_Tbl.GenSailTypeID = dbo.GenSailType_Tbl.GenSailTypeID INNER JOIN
                      dbo.Tier_Tbl ON dbo.QuoteLineItem_Tbl.TierID = dbo.Tier_Tbl.TierID INNER JOIN
                      dbo.Usage_Tbl ON dbo.QuoteLineItem_Tbl.UsageID = dbo.Usage_Tbl.UsageTypeID INNER JOIN
                      dbo.Quote_Tbl ON dbo.QuoteLineItem_Tbl.QuoteID = dbo.Quote_Tbl.QuoteID INNER JOIN
                      dbo.ConstructionSailType_Tbl ON dbo.CostSailType_Tbl.CostSailTypeID = dbo.ConstructionSailType_Tbl.CostSailTypeID AND 
                      dbo.Construction_Tbl.ConstructionID = dbo.ConstructionSailType_Tbl.ConstructionID CROSS JOIN
                      dbo.Adjuster_Tbl
ORDER BY dbo.QuoteLineItem_Tbl.QuoteID DESC